package pers.ascend.spring.cloud.greenwich.service.governance.nacos.consumer.webflux.manage.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import javax.validation.constraints.NotBlank;

/**
 * 说明：
 *
 * @author ascend
 * 2021/3/24 16:35
 */
@RestController
@RequestMapping(path = "/consumer")
@Validated
public class NacosConsumerWebfluxController {
    protected Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private WebClient.Builder webClientBuilder;

    @GetMapping(value = "/hello")
    public String hello(@RequestParam("name") @NotBlank String name) {
        if (log.isInfoEnabled()) {
            log.info("NacosConsumerWebfluxController.hello({})", name);
        }
        Mono<String> retResult = webClientBuilder.build()
                .get()
                .uri("http://nacos-producer/producer/hello?name=" + name)
                .retrieve()
                .bodyToMono(String.class);
        return retResult.toString();
    }
}
